function [ dG ] = OdeTime(t, G,vX,vY, vA, gamma,phi,q,Lambda,r,delta,VB,vC,vD,vDx,betaB )
        
%Calculate model quantities as a function of time
        dG=zeros(4,1);
        [m,ind]=min(abs(vX-G(1)));
        a=vA(ind);
        dF=vY(2,ind);
        W=phi*a;
        lambda=Lambda-a-q;
        %Calculate dV
        dG(1)=(gamma+lambda+delta)*G(1)-W;
        if (G(1)<=VB+0.0000000001)
            dG(1)=0;
        end
        %Calculate F'(V)
        dG(2)=dF*dG(1);
        %Calculate F''(V)
        dG(3)=-dF*(gamma-r);

        %beta
        c=vC(ind);
        [m,ind]=min(abs(vDx-G(1)));
        %D= Price of Debt
        D=vD(ind);
        %Calculate beta'(V)

        dG(4)=min(0,(G(4)-c)/D)*(G(4)>=betaB+0.001);
        


end